<template>
  <div class="mod-home">
    <el-row :gutter="20">
      <el-col :span="12" :xs="24">
        <table>
          <tr>
            <!-- <th>系统名称:</th> -->
            <th>{{$t('message.sysname')}}</th>
            <td>{{$t('message.title')}}</td>
          </tr>
          <tr>
            <th>版本信息:</th>
            <td>v1.1.0</td>
          </tr>
          <tr>
            <th>操作系统:</th>
            <td>{{ sysInfo.osName }}</td>
          </tr>
          <tr>
            <th>系统版本:</th>
            <td>{{ sysInfo.osVersion }}</td>
          </tr>
          <tr>
            <th>系统架构:</th>
            <td>{{ sysInfo.osArch }}</td>
          </tr>
          <tr>
            <th>CPU核数:</th>
            <td>{{ sysInfo.processors }}</td>
          </tr>
          <tr>
            <th>系统内存:</th>
            <td>{{ sysInfo.totalPhysical }}MB</td>
          </tr>
          <tr>
            <th>剩余内存:</th>
            <td>{{ sysInfo.freePhysical }}MB</td>
          </tr>
          <tr>
            <th>内存使用:</th>
            <td>{{ sysInfo.memoryRate }}%</td>
          </tr>
          <tr>
            <th>系统语言:</th>
            <td>{{ sysInfo.userLanguage }}</td>
          </tr>
        </table>
      </el-col>
      <el-col :span="12" :xs="24">
        <table>
          <tr>
            <th>JVM信息:</th>
            <td>{{ sysInfo.jvmName }}</td>
          </tr>
          <tr>
            <th>JVM版本:</th>
            <td>{{ sysInfo.javaVersion }}</td>
          </tr>
          <tr>
            <th>JAVA_HOME:</th>
            <td>{{ sysInfo.javaHome }}</td>
          </tr>
          <tr>
            <th>工作目录:</th>
            <td>{{ sysInfo.userDir }}</td>
          </tr>
          <tr>
            <th>JVM占用内存:</th>
            <td>{{ sysInfo.javaTotalMemory }}MB</td>
          </tr>
          <tr>
            <th>JVM空闲内存:</th>
            <td>{{ sysInfo.javaFreeMemory }}MB</td>
          </tr>
          <tr>
            <th>JVM最大内存:</th>
            <td>{{ sysInfo.javaMaxMemory }}MB</td>
          </tr>
          <tr>
            <th>当前用户:</th>
            <td>{{ sysInfo.userName }}</td>
          </tr>
          <tr>
            <th>CPU负载:</th>
            <td>{{ sysInfo.systemCpuLoad }}%</td>
          </tr>
          <tr>
            <th>系统时区:</th>
            <td>{{ sysInfo.userTimezone }}</td>
          </tr>
        </table>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        sysInfo: {
          osName: '',
          osVersion: '',
          osArch: '',
          processors: 0,
          totalPhysical: 0,
          freePhysical: 0,
          memoryRate: 0,
          userLanguage: '',
          jvmName: '',
          javaVersion: '',
          javaHome: '',
          userDir: '',
          javaTotalMemory: 0,
          javaFreeMemory: 0,
          javaMaxMemory: 0,
          userName: '',
          systemCpuLoad: 0,
          userTimezone: ''
        }
      }
    },
    created () {
      this.getSysInfo()
    },
    methods: {
      getSysInfo () {
        this.$http.get(`${window.SITE_CONFIG['baseURL']}/sys/info`).then(({data}) => {
          if (data && data.code === 0) {
            this.sysInfo.osName = data.info.osName
            this.sysInfo.osVersion = data.info.osVersion
            this.sysInfo.osArch = data.info.osArch
            this.sysInfo.processors = data.info.processors
            this.sysInfo.totalPhysical = data.info.totalPhysical
            this.sysInfo.freePhysical = data.info.freePhysical
            this.sysInfo.memoryRate = data.info.memoryRate
            this.sysInfo.userLanguage = data.info.userLanguage
            this.sysInfo.jvmName = data.info.jvmName
            this.sysInfo.javaVersion = data.info.javaVersion
            this.sysInfo.javaHome = data.info.javaHome
            this.sysInfo.userDir = data.info.userDir
            this.sysInfo.javaTotalMemory = data.info.javaTotalMemory
            this.sysInfo.javaFreeMemory = data.info.javaFreeMemory
            this.sysInfo.javaMaxMemory = data.info.javaMaxMemory
            this.sysInfo.userName = data.info.userName
            this.sysInfo.systemCpuLoad = data.info.systemCpuLoad
            this.sysInfo.userTimezone = data.info.userTimezone
          }
        })
      }
    }
  }
</script>

<style lang="scss">
  .mod-home {
    table {
      width: 100%;
      border: 1px solid #ebeef5;
      border-collapse: collapse;
      th,
      td {
        padding: 12px 10px;
        border: 1px solid #ebeef5;
      }
      th {
        width: 28%;
        text-align: right;
      }
    }
  }
</style>
